class ListNode:
    def __init__(self, val):
        self.val = val
        self.next = None


def print_list(mylist):
    ptr = mylist
    while ptr:
        print(ptr.val, end='->')
        ptr = ptr.next
    print()


list12345 = ListNode(1)
node2 = ListNode(2)
node3 = ListNode(3)
node4 = ListNode(4)
node5 = ListNode(5)
list12345.next = node2
node2.next = node3
node3.next = node4
node4.next = node5

list9 = ListNode(9)

list95 = ListNode(9)
list95.next = ListNode(5)

list999 = ListNode(9)
list999.next = ListNode(9)
list999.next.next = ListNode(9)

list1 = ListNode(1)

list12321 = ListNode(1)
node2 = ListNode(2)
node3 = ListNode(3)
node4 = ListNode(2)
node5 = ListNode(1)
list12321.next = node2
node2.next = node3
node3.next = node4
node4.next = node5

list123321 = ListNode(1)
node2 = ListNode(2)
node3 = ListNode(3)
node4 = ListNode(3)
node5 = ListNode(2)
node6 = ListNode(1)
list123321.next = node2
node2.next = node3
node3.next = node4
node4.next = node5
node5.next = node6

cross_node1 = ListNode(1)
cross_node2 = ListNode(3)
node2 = ListNode(2)
node3 = ListNode(4)
node4 = ListNode(7)
node5 = ListNode(5)
cross_node1.next = node2
node2.next = node3
node3.next = node4
node4.next = node5
cross_node2.next = node3


circle12345 = ListNode(1)
node2 = ListNode(2)
node3 = ListNode(3)
node4 = ListNode(4)
node5 = ListNode(5)
circle12345.next = node2
node2.next = node3
node3.next = node4
node4.next = node5
node5.next = circle12345

circle1 = ListNode(1)
circle1.next = circle1

null_list = None
